Welcome to ‘Twelve-Factor App Methodology’. After watching this video, you will be able to: Describe the characteristics
of modern software development, describe the goal of twelve-factor apps, and identify the twelve factors and describe how these factors map to three phases
of the software delivery lifecycle. In modern software development, the
software is often delivered as a service. Software is centrally hosted and
accessed through the internet. This software is often called a web app or
software-as-a-service, abbreviated to SaaS. You have likely used a variety
of web apps within the last day! When you use the internet to book
reservations or file your taxes, you are interacting with a web app. The twelve-factor app methodology is
suited for these types of applications. Microservices are not a
requirement for twelve-factor apps. However, microservices are
often used in conjunction with the twelve-factor application methodology. The twelve factors can be grouped into the
code, deploy, and operate phases of the software delivery lifecycle. We’ll start with the three factors that map to
the code phase of the software delivery lifecycle. The first is Factor 1, Codebase. You should always track the codebase for an application in a version
control system, such as Git. There is a one-to-one relationship
between a codebase and an app. An app should be contained in a
--single-- codebase. However, there will be multiple
deploys, or instances, of the app. And while the codebase is the
same across those deploys, different app versions can be
present in each deployment. For example, dev or test environments can have
changes that have yet to reach production. Next is Factor 5:
Build, release, and run. This phase demonstrates how a
codebase becomes a production deployment. The build stage compiles the
code, gathers dependencies, and then transforms the codebase into
an executable unit called a build. The release stage combines the build with the deployment’s current configuration
so that the code is ready to run. Then, the run stage implements the application. You should strictly separate these three stages. For example, the code should
not be changeable at runtime, as that would prevent those changes
from being included in the build stage. Factor 10 is dev/prod parity. This factor minimizes the differences between
development and production environments, which is necessary to enable continuous delivery
to quickly promote changes into production. This action reduces the chance
that code runs appropriately in one environment but not in another. Parity is particularly
essential for backend services. If you use MySQL database in production, you should use the same version of MySQL
database in your development environments. Parity helps catch failures
earlier in the development process. And the last code factor we’ll
discuss is Factor 2, Dependencies. An app is only as reliable as
its least reliable dependency. As a result, twelve-factor apps do not rely on the implicit existence of any
packages, dependencies, or tools. You must explicitly declare all dependencies. This way, when a new developer
grabs the codebase, there is no assumption that any dependencies
already exist on their machine. The first deploy factor is Factor 3, Config. The configuration is everything
that can differ between deployments. Different databases are likely
used in staging and production, so a developer should configure that database’s
credentials and location per deployment. You should avoid storing configurations as constants since configurations
might differ among environments. Store the config within the environment variables, which are easy to change across
deployments without changing the code. Factor 4 is Backend services. A twelve-factor app should not distinguish
between local and third-party services. Both should be accessible via a URL or other
location information along with any credentials so that a developer can easily swap out the
backend service without changing the code. For example, if a database experiences
problems, a new database can be spun up and substituted in without having to change code. Factor 6 is Processes. An app executes in an environment
as one or more processes. Processes should be stateless and share nothing. You should store persistent data in
a backend service like a database since memory and filesystems
aren’t shared across processes. If another process handles
a subsequent transaction, the subsequent transaction won’t have
access to data within the prior process. As a result, data needs to be centrally stored. Port binding is Factor 7. When you create a web-facing service, a web server should not be injected
into an application at runtime. Instead, the web app should export HTTP by binding to a port and listening
to incoming requests on that port. You can use port binding
for HTTP and other services. Binding a port is generally done in the code by
declaring a web server library as a dependency. And subsequently, because these
apps are accessible via a URL, they can become backend services for other apps. Next are the operate factors. Let’s
begin with Factor 8, Concurrency. An application runs concurrent
processes to handle the increasing load. And since processes are stateless and share nothing, an application can start additional
processes to scale horizontally and handle additional incoming requests without
creating interdependencies among processes. Factor 9 is Disposability, and it specifies that application processes
require minimal startup time and should end gracefully when terminated. Quick startup lets you quickly
deploy changes to code or config. And you can also easily scale apps
because new deploys start quickly. Factor 11 dictates how to handle logs. Logs give visibility into application performance, so an app should not concern
itself with storing logs. Instead, an application environment should handle logs as a stream of events
written to standard output. The execution environment can capture
the log streams for all running apps, aggregate them, and route
them to their destination. And this action is especially beneficial when
the destination is a log analysis tool. Finally, the last factor is
Factor 12: Admin processes. Admin processes are one-off processes for
managing an app, such as database migration. Admin processes run against a release
using the same codebase and config. Additionally, the application code
should include admin processes so that they remain synchronized with the app. In this video, you learned that: Modern software development
often delivers centrally hosted, web-based, software-as-a-service applications, the twelve-factor app methodology enables developers to create more
efficient SaaS applications, and the twelve factors map to the code, deploy, and operate stages of the
software delivery lifecycle.